package dingadmin

import (
	"time"
)

type TopMessage struct {
	ID   int
	Text string
	Href string
	Time string
}

func (i *Engine) AddTopMessage(id int, text string, href string) {
	i.messages = append(i.messages, TopMessage{
		ID:   id,
		Text: text,
		Href: href,
		Time: time.Now().Format(i.configData.TimeFormat),
	})
}

func searchMessageID(array []TopMessage, id int) int {
	cnt := 0
	for _, i := range array {
		if i.ID == id {
			return cnt
		}
		cnt++
	}
	return -1
}

func (i *Engine) RemoveTopMessage(id int) {
	cnt := searchMessageID(i.messages, id)
	for cnt != -1 {
		i.messages = append(i.messages[:cnt], i.messages[cnt+1:]...)
		cnt = searchMessageID(i.messages, id)
	}
}
